from processFont import humoments
from processFont import variance

import os
import glob
import sys
from string import letters

path = sys.argv[1]

moments = []

# generate moments for all letters for each font
for font in glob.glob(os.path.join(path, '*/')):
    moments.append(humoments(font))

# compute features among Hu moments for each letter across fonts
huvariance = [0,0,0,0,0,0,0]
for i in range(0,26):
    print "Letter {0}:".format(letters[i])
    curmoments = [font[i] for font in moments]
    for j in range(0, 7):
        print "Moment {0}:".format(j + 1)
        print "Sum: {0}".format(sum(letter[j] for letter in curmoments))
        print "Mean: {0}".format(sum(letter[j] for letter in curmoments) / len(curmoments))
        print "Variance: {0}".format(variance([letter[j] for letter in curmoments]))
        huvariance[j] += variance([letter[j] for letter in curmoments])

huvariance = [huvariance[i] / 26 for i in range(0,len(huvariance))]
    
# compute features among Hu moments across different letters for same font
withinfontVariance = [0,0,0,0,0,0,0]
for i in range(0, 7):
    for font in moments:
        withinfontVariance[i] += variance([letter[i] for letter in font])

withinfontVariance = [withinfontVariance[i] / len(moments) for i in range(0,len(withinfontVariance))]

print huvariance
print withinfontVariance
